<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript">
	$(function() {
		talkMainDialog = $('#talk-main-dialog-frame').dialog({
			iconCls : 'icon-user',
			title : '${userSession.name}',
			left : 50,
			resizable : true,
			closed : true,
			closable : true,
			buttons : [ {
				iconCls : 'icon-search',
				handler : function() {
					$("#search-user-dialog-frame").dialog("open");
				}
			} ]
		});

		$('#talk-main-dialog-tabs').tabs({
			fit : true,
			border : false
		});
	});

	//添加联系人
	function addContextToTree(node, groupid) {
		$("#user-friend-tree" + groupid).tree('append', {
			data : [ node ]
		});
	}

	//更新人员在线状态
	function updateFriendState(treeNode) {
		//已登录
		if ('null' != '${userSession.id}' && '' != $.trim('${userSession.id}')) {
			var treeNode = $.parseJSON(treeNode);
			var updateFriendTree = $("#user-friend-tree" + treeNode.attributes.groupid);
			if (updateFriendTree) {
				var updateUserNode = updateFriendTree.tree('find', treeNode.id);
				if (updateUserNode) {
					updateFriendTree.tree('update', {
						target : updateUserNode.target,
						iconCls : treeNode.iconCls
					});
				}
			}
		}
	}

	function updateFriendRemarkName(treeNode, groupid, remarkName) {
		$.ajax({
			type : "POST",
			url : "${pageContext.request.contextPath}/friendAction!updateFreindRemarkName.action",
			data : "friendid=" + treeNode.id + "&pfriendExtend.remarkName=" + remarkName,
			beforeSend : function() {
				$.messager.progress({
					text : '提交数据中....',
					interval : 100
				});
			},
			dataType : "json",
			error : function(info) {
				$.messager.progress('close');
				$.messager.show({
					msg : '更新备注信息失败！',
					title : '提示'
				});
				eval(info.responseText);
			},
			success : function(ret) {
				if (ret.success) {
					//更新节点
					//拼接备注名称
					var friendName = "";
					if ("" == remarkName) {
						if (treeNode.attributes.displayName && "" != $.trim(treeNode.attributes.displayName)) {
							friendName = treeNode.attributes.displayName + "(" + treeNode.attributes.friendName + ")";
						} else {
							friendName = treeNode.attributes.friendName;
						}
					} else {
						friendName = remarkName + "(" + treeNode.attributes.friendName + ")";
					}
					//更新树节点备注名称
					treeNode.attributes.remarkName = remarkName;
					$("#user-friend-tree" + groupid).tree('update', {
						target : treeNode.target,
						text : friendName
					});
				} else {
					$.messager.show({
						msg : ret.msg,
						title : '提示'
					});
				}
				$.messager.progress('close'); //关闭进度条
			}
		});
	}

	//删除好友
	function deleteFriend(treeNode, groupid) {
		$.ajax({
			type : "POST",
			url : "${pageContext.request.contextPath}/friendAction!deleteFriend.action",
			data : "friendid=" + treeNode.id,
			beforeSend : function() {
				$.messager.progress({
					text : '提交数据中....',
					interval : 100
				});
			},
			dataType : "json",
			error : function(info) {
				$.messager.progress('close');
				$.messager.show({
					msg : '删除好友失败！',
					title : '提示'
				});
				eval(info.responseText);
			},
			success : function(ret) {
				if (ret.success) {
					//移除节点
					$("#user-friend-tree" + groupid).tree('remove', treeNode.target);
				}
				$.messager.progress('close'); //关闭进度条
				$.messager.show({
					msg : ret.msg,
					title : '提示'
				});
			}
		});
	}
</script>
<div id="talk-main-dialog-frame" style="width:200px;height:420px;">
	<div id="talk-main-dialog-tabs">
		<div title="联系人" data-options="border:false, href:'${pageContext.request.contextPath}/app/user/talk/contacts_frame.jsp'" style="overflow: hidden;"></div>
	</div>
</div>